import $http from '@/utils/request.js'

export const carouselAPI = () => {
  return $http({
    url: '/home/swiper'
  })
}
export const loginAPI = ({ username, password }) => {
  return $http({
    url: '/user/login',
    method: 'POST',
    data: {
      username, password
    }
  })
}

export const imgAPI = () => {
  return $http({
    url: '/home/swiper'
  })
}
export const conkeyAPI = () => {
  return $http({
    url: '/area/city',
    method: 'GET',
    params: {
      level: 1
    }
  })
}
// AREA|d7233472-6b89-e7e5
export const HousesAPI = () => {
  return $http({
    url: '/houses',
    method: 'GET',
    params: {
      cityId: window.localStorage.getItem('value') || 'AREA|d7233472-6b89-e7e5'
    }
  })
}

export const ditionAPI = ({ id }) => {
  return $http({
    url: '/houses/condition',
    method: 'GET',
    params: {
      id
    }
  })
}

export const mapAPI = ({ id }) => {
  return $http({
    url: '/area/map',
    method: 'GET',
    params: {
      id
    }
  })
}
export const cityHouseAPI = ({ cityId }) => {
  return $http({
    url: '/houses',
    method: 'GET',
    params: {
      cityId
    }
  })
}
// 用户数据
export const gitUserAPI = ({ authorization }) => {
  return $http({
    url: '/user',
    method: 'GET',
    params: {
      authorization
    }
  })
}

export function deepcopy (newObj, oldObj) {
  for (const key in oldObj) {
    if (oldObj[key] instanceof Array) {
      newObj[key] = []
      deepcopy(newObj[key], oldObj[key])
    } else if (oldObj[key] instanceof Object) {
      newObj[key] = {}
      deepcopy(newObj[key], oldObj[key])
    } else {
      key === 'label'
        ? (newObj.text = oldObj[key])
        : (newObj[key] = oldObj[key])
    }
  }
}
